﻿using System.Windows.Forms;
using AMM.Business;

namespace AMM.Forms.Reports {
    public partial class BaseReportSearchControl : UserControl {

        protected delegate object ThreadDelegate();
        protected delegate object ThreadDelegate<T>(T param1);

        public virtual string ReportName { get; private set; }
        public virtual object FetchDatasource() {
            if (this.InvokeRequired) {
                return this.Invoke(new ThreadDelegate(this.CrossedThreadOperation));
            }
            else {
                return this.CrossedThreadOperation();
            }
        }
        public virtual object CrossedThreadOperation() { return null; }
        public virtual void ResetSearch() { }

        protected ReportProcessor _reportProcessor;

        public BaseReportSearchControl() {
            this.InitializeComponent();

            this._reportProcessor = new ReportProcessor();
        }
    }

    public static class StringExtensions {
        public static decimal? ToDecimal(this string s) {
            decimal resultValue;
            if (string.IsNullOrEmpty(s)) {
                return null;
            }
            else {
                if (decimal.TryParse(s, out resultValue)) {
                    return resultValue;
                }
                else {
                    return null;
                }
            }
        }
    }

}
